<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>订单详情</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/comments.css" media="all">
    <link rel="stylesheet" href="css/treeTable.css">
    <style>
        .layui-form-label{
            width: 130px;
        }
        @media screen and (max-width: 450px){
            .layui-form-item .layui-input-inline {
                margin-left: 160px;
            }
        }
        .layui-input-block{
            margin-left: 160px;
        }
        .predictArriveTimediv,.predictArriveTimediv1,.predictDeliveryTimediv,.predictDeliveryTimediv1,.shopRemarksdiv,.shopRemarksdiv1,#selectTable,#selectTable1,.selectTablespan,.selectTable1span,.table_total,.table1_total,.table_total_count,.table1_total_count{
            display: none;
        }
        .table_total,.table1_total,.table_total_count,.table1_total_count{
            text-align: right;
        }
    </style>
</head>
<body>
    <div class="maincontainer">
        <blockquote class="layui-elem-quote">
            订单详情<span class="block_title"></span>
            <button type="button" class="layui-btn layui-btn-sm" style="float: right;margin-top: -4px;" onclick="onback();">返回</button>
        </blockquote>
        <form class="layui-form" action="" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">餐饮总公司名称：</label>
                <div class="layui-form-mid layui-word-aux foodManagerName"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">食堂名称：</label>
                <div class="layui-form-mid layui-word-aux canteenName"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">供应商名称：</label>
                <div class="layui-form-mid layui-word-aux supplierName"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单编号：</label>
                <div class="layui-form-mid layui-word-aux shopOrderNo"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否改单：</label>
                <div class="layui-form-mid layui-word-aux updateStatus"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block table">
                    <span class="selectTablespan">改单前：</span>
                    <table class="layui-hide" id="selectTable" lay-filter="selectTable"></table>
                    <div class="table_total_count">总数：</div>
                    <div class="table_total">合计：</div>
                    <span class="selectTable1span">改单后：</span>
                    <table class="layui-hide" id="selectTable1" lay-filter="selectTable1"></table>
                    <div class="table1_total_count">总数：</div>
                    <div class="table1_total">合计：</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">交货日期：</label>
                <div class="layui-form-mid layui-word-aux deliveryTime"></div>
            </div>
            <div class="layui-form-item predictDeliveryTimediv">
                <label class="layui-form-label">预计发货时间：</label>
                <div class="layui-form-mid layui-word-aux predictDeliveryTime"></div>
            </div>
            <div class="layui-form-item predictDeliveryTimediv1">
                <label class="layui-form-label">预计发货时间：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="predictDeliveryTime" placeholder="">
                </div>
            </div>
            <!-- <div class="layui-form-item predictArriveTimediv">
                <label class="layui-form-label">预计到达时间：</label>
                <div class="layui-form-mid layui-word-aux predictArriveTime"></div>
            </div>
            <div class="layui-form-item predictArriveTimediv1">
                <label class="layui-form-label">预计到达时间：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="predictArriveTime" placeholder="">
                </div>
            </div> -->
            <div class="layui-form-item">
                <label class="layui-form-label">买家备注：</label>
                <div class="layui-form-mid layui-word-aux remarks"></div>
            </div>
            <div class="layui-form-item shopRemarksdiv">
                <label class="layui-form-label">卖家备注：</label>
                <div class="layui-form-mid layui-word-aux shopRemarks"></div>
            </div>
            <div class="layui-form-item shopRemarksdiv1">
                <label class="layui-form-label">卖家备注：</label>
                <div class="layui-input-block">
                    <textarea name="shopRemarks" placeholder="请输入卖家备注" class="layui-textarea" maxlength="140"></textarea>
                  </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block address">
                    <div style="margin-bottom: 8px;">
                        <i class="layui-icon layui-icon-location"></i>
                        <span class="receiveUser"></span>
                        <span class="receiveTelephone"></span>
                    </div>
                    <div style="margin-left: 20px;">
                        <span>地址：</span>
                        <span class="receiveAddressInfo"></span>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnDiv">
            </div>
        </form>
    </div>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>

    layui.config({
        base: 'plugins/layui/modules/',
    }).use(['http', 'form', 'laydate', 'table', 'treeTable'], function() {
        var http = layui.http,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table,
            treeTable = layui.treeTable;

        var type = http.getPid('type');
        window.onback = function() {
            if(type){
                $(window.parent.document).find('.maincontainer').show()
                $(window.parent.document).find('#my_iframe').hide()
                window.parent.layui.table.reload('selectTable')
            }else{
                window.history.back()
            }
        }
        
        var shopOrderNo = http.getPid('id')
        var supplierAcceptOrderParamsList
        init()
        function init(){
            http.get('admin/shop/order/findById',{
                shopOrderNo: shopOrderNo
            },function(res){
                if(res.code == 200){
                    var data = res.data
                    $('.block_title').html(data.orderStatusVo.orderStatus==3?' - 待付款':(data.orderStatusVo.orderStatus==4?' - 待接单':(data.orderStatusVo.orderStatus==5?' - 待发货':(data.orderStatusVo.orderStatus==6?' - 待确认':(data.orderStatusVo.orderStatus==8?' - 已发货':(data.orderStatusVo.orderStatus==9?' - 已完成':(data.orderStatusVo.orderStatus==10?' - 已取消':'')))))))
                    $('.foodManagerName').html(data.foodManagerName)
                    $('.canteenName').html(data.canteenName)
                    $('.supplierName').html(data.supplierName)
                    $('.shopOrderNo').html(data.shopOrderNo)
                    $('.updateStatus').html(data.orderStatusVo.updateStatus==1?'是':'否')
                    $('.deliveryTime').html(data.deliveryTime.split(' ')[0])
                    // if(data.predictArriveTime){
                    //     $('.predictArriveTimediv').show()
                    //     $('.predictArriveTime').html(data.predictArriveTime)
                    // }
                    if(data.predictDeliveryTime){
                        $('.predictDeliveryTimediv').show()
                        $('.predictDeliveryTime').html(data.predictDeliveryTime.substring(0, data.predictDeliveryTime.length-3))
                    }
                    if(data.shopRemarks){
                        $('.shopRemarksdiv').show()
                        $('.shopRemarks').html(data.shopRemarks)
                    }
                    $('.remarks').html(data.remarks?data.remarks:'无')
                    $('.receiveUser').html(data.receiveUser)
                    $('.receiveTelephone').html(data.receiveTelephone)
                    $('.receiveAddressInfo').html(data.receiveAddressInfo)

                    if(data.updateStatus == 0){ // 未改单
                        $('#selectTable').show()
                        $('.table_total_count').show()
                        $('.table_total').show()
                        // http.table1({
                        //     elem: '#selectTable',
                        //     id: 'selectTable',
                        //     cols: [[
                        //         {field:'goodNo', title: '商品编号', align : 'center'},
                        //         {field:'productName', title: '商品名称', align : 'center'},
                        //         {field:'price', title: '单价', align : 'center',totalRow: true},
                        //         {field:'goodCount', title: '数量', align : 'center'},
                        //         {field:'stallName', title: '档口名称', align : 'center'}
                        //     ]],
                        //     data: data.singleOrderInfoVoList
                        // })
                        for(var i=0;i<data.canteenSingleOrderGroupWithGoodInfoVoList.length;i++){
                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].id = i
                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].total = (data.canteenSingleOrderGroupWithGoodInfoVoList[i].goodCount * data.canteenSingleOrderGroupWithGoodInfoVoList[i].price).toFixed(2)
                            for(var j=0;j<data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList.length;j++){
                                data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].id = 'child'+i
                                data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].pid = i
                                data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].total = (data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount * data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].price).toFixed(2)
                            }
                        }
                        treeTable.render({
                            elem: '#selectTable',
                            data: data.canteenSingleOrderGroupWithGoodInfoVoList,
                            tree: {
                                iconIndex:1
                            },
                            id: 'selectTable',
                            cols: [
                                {type: 'numbers', title: '序号',width: 60},
                                // {field:'goodNo', title: '商品编号', align : 'center'},
                                {field:'productName', title: '商品名称', align : 'center',
                                    templet: function(d){
                                        var html = ''
                                        html += '<a class="buttoncolor" lay-event="detail">'+d.productName+'</a>'
                                        return html
                                    }
                                },
                                {field:'skuName', title: '规格', align : 'center'},
                                {field:'unitName', title: '单位', align : 'center',
                                    templet: function(d){
                                        return d.unitName?d.unitName:d.unit
                                    }
                                },
                                {field:'price', title: '单价', align : 'center'},
                                {field:'goodCount', title: '数量', align : 'center'},
                                {field:'total', title: '小计', align : 'center'},
                                {field:'stallName', title: '档口名称', align : 'center'}
                            ],
                            style: 'margin-top:0;',
                            tree: {
                                id: 'id',
                                pidName: 'pid',  // pid的字段名
                                childName: 'singleOrderInfoVoList',  // children的字段名
                            }
                        })
                        // var sum = 0
                        // for(var p=0;p<data.singleOrderInfoVoList.length;p++){
                        //     sum += data.singleOrderInfoVoList[p].price*data.singleOrderInfoVoList[p].goodCount
                        // }
                        $('.table_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block;">'+data.goodCount+'</span>')
                        $('.table_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block;">￥'+data.orderTotalMoney.toFixed(2)+'</span>')
                    }else{ // 已改单
                        $('#selectTable').show()
                        $('.selectTablespan').show()
                        $('#selectTable1').show()
                        $('.selectTable1span').show()
                        $('.table_total_count').show()
                        $('.table_total').show()
                        $('.table1_total_count').show()
                        $('.table1_total').show()
                        // http.table1({
                        //     elem: '#selectTable',
                        //     id: 'selectTable',
                        //     cols: [[
                        //         {field:'goodNo', title: '商品编号', align : 'center'},
                        //         {field:'productName', title: '商品名称', align : 'center'},
                        //         {field:'originalGoodPrice', title: '单价', align : 'center',
                        //             templet: function(d){
                        //                 return d.originalGoodPrice?d.originalGoodPrice:d.price
                        //             }
                        //         },
                        //         {field:'originalGoodCount', title: '数量', align : 'center',
                        //             templet: function(d){
                        //                 return d.originalGoodCount?d.originalGoodCount:d.goodCount
                        //             }
                        //         },
                        //         {field:'stallName', title: '档口名称', align : 'center'}
                        //     ]],
                        //     data: data.singleOrderInfoVoList
                        // })
                        var count = 0
                        for(var i=0;i<data.canteenSingleOrderGroupWithGoodInfoVoList.length;i++){
                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].id = i
                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].total = ((data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodCount?data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodPrice?data.canteenSingleOrderGroupWithGoodInfoVoList[i].originalGoodPrice:data.canteenSingleOrderGroupWithGoodInfoVoList[i].price)).toFixed(2)

                            data.canteenSingleOrderGroupWithGoodInfoVoList[i].total1 = (((data.canteenSingleOrderGroupWithGoodInfoVoList[i].refreshGoodCount||data.canteenSingleOrderGroupWithGoodInfoVoList[i].refreshGoodCount===0)?data.canteenSingleOrderGroupWithGoodInfoVoList[i].refreshGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].price)).toFixed(2)

                            for(var j=0;j<data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList.length;j++){
                                data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].id = 'child'+i
                                data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].pid = i
                                data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].total = ((data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodPrice?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodPrice:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].price)).toFixed(2)

                                data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].total1 = (((data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].refreshGoodCount||data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].refreshGoodCount===0)?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].refreshGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount) * (data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].price)).toFixed(2)

                                count += data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount?data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].originalGoodCount:data.canteenSingleOrderGroupWithGoodInfoVoList[i].singleOrderInfoVoList[j].goodCount
                            }
                        }
                        treeTable.render({
                            elem: '#selectTable',
                            data: data.canteenSingleOrderGroupWithGoodInfoVoList,
                            tree: {
                                iconIndex:1
                            },
                            id: 'selectTable',
                            cols: [
                                {type: 'numbers', title: '序号',width: 60},
                                // {field:'goodNo', title: '商品编号', align : 'center'},
                                {field:'productName', title: '商品名称', align : 'center',
                                    templet: function(d){
                                        var html = ''
                                        html += '<a class="buttoncolor" lay-event="detail">'+d.productName+'</a>'
                                        return html
                                    }
                                },
                                {field:'skuName', title: '规格', align : 'center'},
                                {field:'unitName', title: '单位', align : 'center',
                                    templet: function(d){
                                        return d.unitName?d.unitName:d.unit
                                    }
                                },
                                {field:'originalGoodPrice', title: '单价', align : 'center',
                                    templet: function(d){
                                        return d.originalGoodPrice?d.originalGoodPrice:d.price
                                    }
                                },
                                {field:'originalGoodCount', title: '数量', align : 'center',
                                    templet: function(d){
                                        return d.originalGoodCount?d.originalGoodCount:d.goodCount
                                    }
                                },
                                {field:'total', title: '小计', align : 'center'},
                                {field:'stallName', title: '档口名称', align : 'center'}
                            ],
                            style: 'margin-top:0;',
                            tree: {
                                id: 'id',
                                pidName: 'pid',  // pid的字段名
                                childName: 'singleOrderInfoVoList',  // children的字段名
                            }
                        })
                        // var sum = 0
                        // for(var p=0;p<data.singleOrderInfoVoList.length;p++){
                        //     sum += (data.singleOrderInfoVoList[p].originalGoodPrice?data.singleOrderInfoVoList[p].originalGoodPrice:data.singleOrderInfoVoList[p].price)*(data.singleOrderInfoVoList[p].originalGoodCount?data.singleOrderInfoVoList[p].originalGoodCount:data.singleOrderInfoVoList[p].goodCount)
                        // }
                        $('.table_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block;">'+count+'</span>')
                        $('.table_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block;">￥'+data.originalOrderAmount.toFixed(2)+'</span>')
                        // http.table1({
                        //     elem: '#selectTable1',
                        //     id: 'selectTable1',
                        //     cols: [[
                        //         {field:'goodNo', title: '商品编号', align : 'center'},
                        //         {field:'productName', title: '商品名称', align : 'center'},
                        //         {field:'price', title: '单价', align : 'center'},
                        //         {field:'goodCount', title: '数量', align : 'center'},
                        //         {field:'stallName', title: '档口名称', align : 'center'}
                        //     ]],
                        //     data: data.singleOrderInfoVoList
                        // })
                        treeTable.render({
                            elem: '#selectTable1',
                            data: data.canteenSingleOrderGroupWithGoodInfoVoList,
                            tree: {
                                iconIndex:1
                            },
                            id: 'selectTable1',
                            cols: [
                                {type: 'numbers', title: '序号',width: 60},
                                // {field:'goodNo', title: '商品编号', align : 'center'},
                                {field:'productName', title: '商品名称', align : 'center',
                                    templet: function(d){
                                        var html = ''
                                        html += '<a class="buttoncolor" lay-event="detail">'+d.productName+'</a>'
                                        return html
                                    }
                                },
                                {field:'skuName', title: '规格', align : 'center'},
                                {field:'unitName', title: '单位', align : 'center',
                                    templet: function(d){
                                        return d.unitName?d.unitName:d.unit
                                    }
                                },
                                {field:'price', title: '单价', align : 'center'},
                                {field:'goodCount', title: '数量', align : 'center',
                                    templet: function(d){
                                        return (d.refreshGoodCount||d.refreshGoodCount===0)?d.refreshGoodCount:d.goodCount
                                    }
                                },
                                {field:'total1', title: '小计', align : 'center'},
                                {field:'stallName', title: '档口名称', align : 'center'}
                            ],
                            style: 'margin-top:0;',
                            tree: {
                                id: 'id',
                                pidName: 'pid',  // pid的字段名
                                childName: 'singleOrderInfoVoList',  // children的字段名
                            }
                        })
                        // var sum1 = 0
                        // for(var q=0;q<data.singleOrderInfoVoList.length;q++){
                        //     sum1 += data.singleOrderInfoVoList[q].price*data.singleOrderInfoVoList[q].goodCount
                        // }
                        $('.table1_total_count').html('总数：<span style="color: #fbaf7e;width: 100px;display: inline-block;">'+data.goodCount+'</span>')
                        $('.table1_total').html('合计：<span style="color: #fbaf7e;width: 100px;display: inline-block;">￥'+data.orderTotalMoney.toFixed(2)+'</span>')
                    }
                    
                    // 监听表格事件
                    treeTable.on('tool(selectTable)', function(obj){
                        var data = obj.data;
                        if(obj.event == 'detail'){
                            location.href="productDetail.html?id="+data.productId
                        }
                    });
                }else{
                    layer.msg(res.msg)
                }
            })
        }
        
    })
</script>
</body>
</html>